<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('项目管理')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="col-sm-12 search-collapse">
        <form id="data-form">
            <div class="select-list">
                <ul>
                    <li>
                        </label>课程类型：</label>
                        <select name="courseId"  style="margin-right: 25px">
                            <option value="">全部</option>
                            <option value="28">运动力课程</option>
                            <option value="29">感统课程</option>
                        </select>
                    </li>
                    <li>
                        </label>班级类型：</label>
                        <select name="classType"  style="margin-right: 25px">
                            <option value="">全部</option>
                            <option value="1">常规班</option>
                            <option value="2">集训班</option>
                        </select>
                    </li>
                    <li>
                        <select name="ageGrade" id="ageGrade"
                                th:with="type=${@dict.getType('age_grade')}">
                            <option value="">全部</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                            </option>
                        </select>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 新增训练计划表
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    // 权限

    // 字典
    var courseId = [[${@dict.getType('course_id')}]];
    var classType = [[${@dict.getType('class_type')}]];
    var gradeList = [[${@dict.getType('grade_list')}]];
    var ageList = [[${@dict.getType('age_list')}]];
    var ageGrade = [[${@dict.getType('age_grade')}]];
    var prefix = ctx + "business/classPlan";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            queryParams: queryParams,
            modalName: "数据",
            columns: [
                {
                    field: 'id',
                    title: '计划表编号',
                },
                {
                    field: 'sort',
                    title: '排序编号',
                },
                {
                    field: 'planName',
                    title: '训练计划表名称',
                },
                {
                    field: 'courseId',
                    title: '课程名称',
                    formatter: function (value, row, index) {
                        for (var k in courseId) {
                            if (courseId[k].dictValue == value.toString()) {
                                return courseId[k].dictLabel
                            }
                        }
                        return value;
                    }
                },
                {
                    field: 'ageGrade',
                    title: '年龄年级段',
                    formatter: function (value, row, index) {
                        for (var k in ageGrade) {
                            if (ageGrade[k].dictValue == value.toString()) {
                                return ageGrade[k].dictLabel
                            }
                        }
                        return value;
                    }
                },
                {
                    field: 'classType',
                    title: '班级类型',
                    formatter: function (value, row, index) {
                        for (var k in classType) {
                            if (classType[k].dictValue == value.toString()) {
                                return classType[k].dictLabel
                            }
                        }
                        return value;
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if ($.common.isNotEmpty(value)) {
                            return value == 0 ? "已启用" : "已停用";
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'updateTime',
                    title: '最后编辑时间',
                },
                {
                    field: 'updateUser',
                    title: '编辑人',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="viewTrainAmount(\'' + row.id + '\',\'' + row.totalClassTimes + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if (row.status == 0) {
                            actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\',\'1\')"><i class="fa fa-edit"></i>停用</a> ');
                        }
                        if (row.status == 1) {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\',\'0\')"><i class="fa fa-edit"></i>启用</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var selectIndex = window.parent.document.getElementById('parentSchoolList').selectedIndex;
        if (selectIndex >= 0) {
            var centerId = window.parent.document.getElementById('parentSchoolList').options[selectIndex].value;
            var search = $.table.queryParams(params);
            search.centerId = centerId;
        }
        return search;
    }

    function viewTrainAmount(id, totalClassTimes) {
        var url = ctx + "business/classPlanDetail/list/" + id + "/" + totalClassTimes;
        $.modal.openTab("训练计划编辑", url);
    }

    function updateStatus(id, status) {
        var reqData = {
            "id": id,
            "status": status
        }
        $.ajax({
            url: prefix + "/updateStatus",
            type: "post",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify(reqData),
            success: function (result) {
                $.table.refresh();
            }
        })

    }
</script>
</body>

</html>